<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .login-box{
            width: 600px;
            height: 400px;
            padding: 10px;
            margin-left: 600px;
            margin-top: 300px;
            border: 1px solid;
            border-radius:10px ;

        }
        .logo img{
            height: 260px;
            width: 240px;
        }

        .logo{
            float: left;
            width: 40%;
            height: 90%;
            padding: 5px;
            line-height: 100%;
            text-align: center;
            border: 1px solid;
        }


        .login-content{
            float: left;
            margin-left: 6%;
            padding: 5px;
            border: 1px solid;
            height: 90%;
            width: 50%;
        }

        .user-box{
            padding: 5%;
            margin-top: 30px;

        }


        .row{
            float: left;
            width: 100%;
            height: 50px;
            padding: 5px;
            line-height: 60px;
            /* border: 1px solid;*/
        }

        .row input {
            display: inline-block;
            border-radius: 8%;
            height: 60%;
            width: 90%;
        }

        .vify input {
            width: 20% !important;
        }

        .btn-login{
            display: inline-block;
            border-radius: 20%;
            border: 1px transparent;
            height: 30px;
            width: 100px;
        }

        .btn-success{
            background-color: greenyellow;
        }

        .offset{
            margin-left: 40%;

        }

    </style>
    <script src="jQuery/jquery-3.6.1.js"></script>

</head>
<body>
<!--<h1>权限五张表，MyBatis实现</h1>-->
<!--<div>-->
<!--&lt;!&ndash;    用户名：<input type="text" id="username"><br>&ndash;&gt;-->
<!--&lt;!&ndash;    密码：<input type="text" id="password"><br>&ndash;&gt;-->
<!--&lt;!&ndash;    验证码：<input type="text" id="verifyCode"><img src="geVerifyCode">&ndash;&gt;-->
<!--&lt;!&ndash;    <button id="btnLogin">登录</button>&ndash;&gt;-->
<!--</div>-->

<div class="login-box">
    <div class="logo">
        logo
        <img src="../img/logo.jpg">
    </div>

    <div class="login-content">

        <div class="user-box">
            <div class="row">
                <input type="text" id="username" placeholder="username">
            </div>
            <div class="row">
                <input type="text" id="password" placeholder="password">
            </div>
            <div class="row vify">
                验证码：<input type="text" id="verifyCode"><img width="40%" height="70%" src="geVerifyCode">
            </div>
            <div class="row">
                <button class="offset btn-login btn-success" id="btnLogin">登录</button>
            </div>

        </div>

    </div>

</div>

<script>
    $(document).ready(function () {
        $("#btnLogin").click(function () {
            $.ajax({
                url: "login",
                type: "post",
                dataType: "json",
                data: {
                    username: $("#username").val(),
                    password: $("#password").val(),
                    verifyCode:$("#verifyCode").val()
                },
                success: function (result) {
                    // alert(JSON.stringify(result))
                    console.log(JSON.stringify(result))
                    username = result.object.username
                    // alert(username)
                    rolename = result.object.userRole.role.name
                    // alert(rolename)
                    localStorage.setItem("username",username)
                    localStorage.setItem("rolename",rolename)
                    $(location).attr("href","welcome.html")
                },
                error: function (result) {
                }
            })
        })
    })
</script>
</body>
</html>
